package cn.iocoder.yudao.module.shop.dal.mysql.accountrecord;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.shop.dal.dataobject.accountrecord.ShopAccountRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.shop.controller.admin.accountrecord.vo.*;

/**
 * 收支记录 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface ShopAccountRecordMapper extends BaseMapperX<ShopAccountRecordDO> {

    default PageResult<ShopAccountRecordDO> selectPage(ShopAccountRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopAccountRecordDO>()
                .betweenIfPresent(ShopAccountRecordDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(ShopAccountRecordDO::getType, reqVO.getType())
                .eqIfPresent(ShopAccountRecordDO::getIsFixed, reqVO.getIsFixed())
                .eqIfPresent(ShopAccountRecordDO::getFixedType, reqVO.getFixedType())
                .eqIfPresent(ShopAccountRecordDO::getTenantId, reqVO.getTenantId())
                .betweenIfPresent(ShopAccountRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopAccountRecordDO::getId));
    }

    default List<ShopAccountRecordDO> selectList(ShopAccountRecordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopAccountRecordDO>()
                .betweenIfPresent(ShopAccountRecordDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(ShopAccountRecordDO::getType, reqVO.getType())
                .eqIfPresent(ShopAccountRecordDO::getIsFixed, reqVO.getIsFixed())
                .eqIfPresent(ShopAccountRecordDO::getFixedType, reqVO.getFixedType())
                .betweenIfPresent(ShopAccountRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopAccountRecordDO::getId));
    }

    default List<ShopAccountRecordDO> selectListByTimeNoFixed(LocalDateTime startTime, LocalDateTime endTime, Long tenantId){
        return selectList(new LambdaQueryWrapperX<ShopAccountRecordDO>()
                .eq(ShopAccountRecordDO::getTenantId, tenantId)
                .between(ShopAccountRecordDO::getPayTime, startTime, endTime)
                .eq(ShopAccountRecordDO::getIsFixed, false));
    }

    default List<ShopAccountRecordDO> selectListFixed(Long tenantId){
        return selectList(new LambdaQueryWrapperX<ShopAccountRecordDO>()
                .eq(ShopAccountRecordDO::getTenantId, tenantId)
                .eq(ShopAccountRecordDO::getIsFixed, true));
    }

}
